<template>
  <div class="tree-container">
    <!--tree-->
    <!--:levStatus="levStatus"-->
    <!--:searchText.sync="selectId"-->
        <tree ref="tree"
              @treeGetlists="treeGetlists"
        ></tree>

    <div class="tree-container-right vw20" >
            <!-- 这是组件要插入的地方 -->
      <div class="page-component-wrap animated fadeIn">
        <el-row style="margin:0px;margin-bottom: 10px;">
          <el-col :span="14">
            <div class="grid-content bg-purple-dark">
              <el-autocomplete
                style="width:80%"
                v-model="searchText"
                :fetch-suggestions="querySearchAsync"
                :debounce="1000"
                placeholder="请输入查询编码,关键字等"
                @select="handleSelect"
                size="medium"
                clearable
                suffix-icon="el-icon-edit"
                class="immm"
              >
                <template slot-scope="{ item }">
                  <span class="partName">{{ item.codeExplain.fullCodeNo}}</span>
                  <span class="fullname">{{ item.codeExplain.explainText  }}</span>
                  <!--<span class="level">{{ item.level }}</span>-->
                </template>
              </el-autocomplete>
            </div>
          </el-col>

          <el-col :span="10">
            <el-button type="primary" @click="$refs.devref.addDevice(1)" icon="el-icon-plus">发起申请备件</el-button>
            <el-button type="info" @click="$refs.devref.addDevice(0)" icon="el-icon-plus">管理员添加备件</el-button>
          </el-col>
        </el-row>

<!-- add edit item -->

        <!--:levStatus="levStatus"-->
        <device ref="devref"
               :treeNodeData.sync="treeNodeData"
               @childGetList="$refs.tbcom.getList()"
        ></device>
<!--table-->
        <tbcom ref="tbcom"
          @updateRow="updateRow"
          @childGetList="$refs.tbcom.getList()"
          @setCheckedKey="setCheckedKey"
        ></tbcom>

      </div>
    </div>
  </div>
</template>
<script>
  import tree from './comp/deviceTree'
  // import 'filters/handleNum.js'
  import { fetchGet} from '@/api/common'
  import { $err, $suc, ERRS, SUCS,$msg} from '@/utils'
  // import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  import device from './comp/deviceComp' // Secondary package based on el-pagination
  import tbcom from './comp/tbApply'

  export default {
    name: 'applyCode',
    components: {tree,  device,tbcom},
    mounted() {
      // this.getList()
      // this.allList(0) //根级level select
    },
    data() {
      return {
        //弹出层
        listLoading: false,  //加载动画
        dialogStatus: '', //值对应textMap中的属性
        //分页搜索
        total: 0,

        searchText: '',
        searchData: {},
        changeSearchData:[{}],
        treeNodeData: {}, //添加修改时保存父级信息

        formSearch: {},
        temp: {},
      };
    },

    methods: {
      // tree点击分发事件
      treeGetlists(data){
        this.treeNodeData=data
        this.$refs.tbcom.getList(data)
      },
      updateRow(row){
        this.$refs.devref.updateDevice(row)
      },
      //输入间隔查询
      querySearchAsync(queryString, cb) {

        if (queryString.length > 0) {
          fetchGet(`sparepartscode/parts/condition/false?page=1&size=1&searchText=${queryString}`).then(res => {

            console.log(res);
            if (res.code == 0) {
              let dat = res.data.content;
              console.log(dat);
              if (dat.length > 0) {
                cb(dat);
                this.restaurants = dat
              } else {
                cb([]);
                this.restaurants = []
              }
            } else {
              ERRS(res.message)
            }
          })
        } else {
          // cb([]);
        }
      },

      //搜索结果选择
      handleSelect(item) {
        this.searchText = item.codeExplain.fullCodeNo
        this.searchData = item
        this.$refs.tree.handleNodeClick(item.codeExplain.parent)

      },
      //table列点击 tree响应展开
      setCheckedKey(id) {
        this.$refs.tree.setCheckedKey(id)
      }
    },
  }
</script>
<style lang="scss">
  @import './comp/index.scss';

</style>

